home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1999 May / Software of the Month - Ultimate Collection Shareware 261.iso / mac / Business / YellowEdit / Yellow Extension Toolkit / YE main.c next >
Encoding:
C/C++ Source or Header  |  1998-09-13  |  3.2 KB  |  111 lines  |  [TEXT/CWIE]

  1. //ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
  2. //    YELLOW EXTENSION TOOLKIT
  3. //    File Name   :    YE main.c
  4. //    ⌐ 1998 by Rocco Moliterno. All Right Reserved
  5. //ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ
  6.  
  7. #include "WASTE.h"
  8. // In order to use Waste functions, you need to add WASTE and the Libraries WASTE requires
  9.  
  10. #include "YE proto.h"
  11. #include "YE main.h"
  12.  
  13. #if GENERATING68K
  14.     #include <SetUpA4.h>
  15.     #include <A4Stuff.h>
  16. #else
  17.     ProcInfoType __procinfo = uppYellowEntryProcInfo;
  18. #endif
  19.  
  20. pascal void main(YEBlockPtr params)
  21. {
  22.     #if GENERATING68K
  23.         EnterCodeResource();
  24.     #endif
  25.  
  26. //---------------------------your code here
  27.  
  28.      GoAction(params);
  29.  
  30. //---------------------------end your code
  31.  
  32.     #if GENERATING68K
  33.         ExitCodeResource();
  34.     #endif
  35.     
  36. }
  37.  
  38. #pragma mark EXAMPLE CODE
  39.  
  40. void GoAction(YEBlockPtr params)
  41. {
  42.  
  43. // Sanity: YellowEdit requires always params->signature = 'yllw'    
  44.     if(params->signature==yellowSignature){
  45.         ParamText("\pYellow Extension sanity check: good, YellowEdit calls me!" ,"\p", "\p",  "\p");
  46.         NoteAlert(128, nil);
  47.     }
  48.     else        // The caller isn't YellowEdit, we return, unless if you're writing
  49.         return; // the extension for another application, or else you perform a job
  50.                 // without considering the caller.
  51.  
  52. // Unless we modify directly input data, we can ignore, here, any inputs parameters then
  53. // make our job: display alert/dialog, play sound, get file, play game and so on. 
  54. // We MUST always check the input parameters if we want to modify directly some 
  55. // data ex:
  56. //
  57. //  if(params->sFile)
  58. //        if((iErr=ResolveAlias(nil,params->sFile, &target, &wasChanged))!=noErr)
  59. //            iErr=FSpDelete(&target);
  60. //
  61. // or else:
  62. //  if(params->sWaste)
  63. //        WEPaste(params->sWaste);
  64. // in the following example, we don't modify directly any data but we make checks for security.
  65.  
  66.     
  67. // Remember: the calling application has responsibility to dispose any valid but unused, 
  68. // handle returned by extensions.
  69. //----------------------------------------------------------------------------------
  70.     if( (!params->sWaste) && 
  71.         (!params->sText)  &&
  72.         (!params->sFile)  &&
  73.         (!params->sList)){
  74.         ParamText("\pOh no! there's no window open!! I will return some text into a new window","\p" ,"\p" ,  "\p");
  75.         NoteAlert(128, nil);
  76.         params->rNew=true; //put new TEXT into a new window.
  77.         }    
  78.  
  79.     if(params->sWaste || params->sText){
  80.         ParamText( "\pThe call contains a valid text-related request","\p" ,"\p" ,  "\p");
  81.         NoteAlert(128, nil);
  82.  
  83.         ParamText("\pI will return some text to existing window...","\p" ,"\p" ,  "\p" );
  84.         NoteAlert(128, nil);
  85.     }
  86.  
  87.     params->rText=GetResource('TEXT',128);
  88.     DetachResource(params->rText);
  89.     HLock(params->rText);
  90.     params->rStyles=GetResource('styl',128);
  91.     DetachResource(params->rStyles);
  92.     HLock(params->rStyles);
  93.     
  94.     if(params->sFile){
  95.         Boolean wasChanged;
  96.         FSSpec  target;        
  97.         if(ResolveAlias(nil,params->sFile, &target, &wasChanged)==noErr)
  98.             ParamText( "\pThe call contains an AliasHandle:",target.name , "\p" ,  "\p");
  99.         else
  100.             ParamText( "\pThe call contains an AliasHandle, but can't resolve this damned alias!","\p"  , "\p" ,  "\p");
  101.         NoteAlert(128, nil);
  102.         }
  103.  
  104.     if(params->sList){
  105.         ParamText("\pThe call contains a List Handle","\p" ,"\p" ,  "\p");
  106.         NoteAlert(128, nil);
  107.         }
  108.  
  109. }
  110.  
  111.